import 'package:flutter/material.dart';
import 'package:wechat_app/pages/login/login.dart';
import 'package:wechat_app/pages/login/register.dart';

class MainPage extends StatelessWidget {
  const MainPage({super.key});

  void action(BuildContext context, String value) {
    Navigator.of(context)
        .push(MaterialPageRoute(builder: (BuildContext context) {
      return value == "0" ? const Login() : const Register();
    }));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: const BoxDecoration(
            image: DecorationImage(
                image: AssetImage('assets/images/bg.jpeg'), fit: BoxFit.cover)),
        alignment: Alignment.bottomCenter,
        child: SafeArea(
            minimum: const EdgeInsets.all(20),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: ["登录", "注册"].map((e) {
                  final bool isLogin = e == "登录";
                  return InkWell(
                    child: Container(
                      alignment: Alignment.center,
                      height: 40,
                      width: (MediaQuery.of(context).size.width - 50) / 2,
                      decoration: BoxDecoration(
                          color: Colors.white.withOpacity(0.12),
                          borderRadius:
                              const BorderRadius.all(Radius.circular(4))),
                      child: Text(
                        e,
                        style: TextStyle(
                            color: isLogin ? Colors.white : Colors.green,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                    ),
                    onTap: () => action(context, isLogin ? '0' : '1'),
                  );
                }).toList())),
      ),
    );
  }
}
